<template>
    <div class="pad">
        <!-- search start -->
        <searchBar
            placeHolder="请输入收件人姓名"
            :isShowDate="false"
            @handleSearch="init"
            :left="20"
            :isShowAdd="true"
            btnText="导出Excel"
            @handleAdd="handleExcel"
        />
        <!-- search end -->
        <!-- table start -->
        <tableDataEl
            :page.sync="page"
            :pageSize="pageSize"
            :tableData="tableData.list"
            :tableLabel="tableLabel"
            :pageCount="tableData.rows"
            v-loading="loading"
        />
        <!-- table end -->
    </div>
</template>

<script>
    import tableDataEl from '@/views/Setup/common/table'
    export default {
        name: "equipment",
        components: {
            tableDataEl
        },
        data () {
            return {
                page: 1,
                pageSize: 8,
                tableData: {},
                tableLabel: [
                    {
                        label: '收件人',
                        prop: 'man'
                    },
                    {
                        label: '联系电话',
                        prop: 'phone'
                    },
                    {
                        label: '收件地址',
                        detailAddress: true
                    },
                    {
                        label: '状态',
                        showText: true,
                        btnText: '未导出'
                    },
                    {
                        label: '支付时间',
                        prop: 'time'
                    }
                ],
                loading: false
            }
        },
        methods: {
            async init ( search = '' ) {  //初始化
                this.loading = true;
                let paramsStr = {key: search['search'], page: this.page, pageSize: this.pageSize};
                let res = await this.api.owner_unSendList(paramsStr);
                res.code ? this.tableData = res.data: this.$message(res.msg);
                this.loading = false;
            },
            async handleExcel () {
                this.$confirm('', {
                    title: "确认导出吗？",
                    message: '确认后若出现提示弹框请点击保存, 否则将会丢失文件',
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    new Promise((res,rej) => {
                        window.location.href = `${process.env.VUE_APP_URL}auditAdmin/ExportExcel/exObdUnSend`;
                        res()
                    }).then(() => {
                        setTimeout(()=> {
                            this.init()
                        }, 1500)
                    }).catch(()=> {})
                });

            }
        },
        mounted () {
            this.init()
        },
        watch: {
            page () {
                this.init()
            },
            pageSize () {
                this.init()
            }
        }
    }
</script>

<style scoped>
    .pad {
        padding:10px;
    }
</style>
